package cn.leedsoft.and.crimeintent.controller.crime_intent;

import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import cn.leedsoft.and.crimeintent.common.PictureUtil;

/**
 * Created by leeds on 2016/8/9 10:24.
 */
public class ImageDialogFragment extends DialogFragment {
    private String mImagePath;
    private PictureUtil mPictureUtil;
    private ImageView mImageView;
    public static final String TAG = ImageDialogFragment.class.getSimpleName();
    public static final String INTENT_KEY_IMAGE_PATH = ImageDialogFragment.class.getName() + ".intent.key.image.path";

    public static ImageDialogFragment newInstance(String imagePath) {
        Bundle args = new Bundle();
        args.putSerializable(INTENT_KEY_IMAGE_PATH, imagePath);

        ImageDialogFragment fragment = new ImageDialogFragment();
        fragment.setArguments(args);
        fragment.setStyle(ImageDialogFragment.STYLE_NO_TITLE, 0);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mImagePath = getArguments().getString(INTENT_KEY_IMAGE_PATH);
        mPictureUtil = new PictureUtil(getActivity());
        mImageView = new ImageView(getActivity());
        mImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ImageDialogFragment.this.dismiss();
            }
        });

        mPictureUtil.showPic(mImageView, mImagePath);
        return mImageView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        mPictureUtil.clearPic(mImageView);
    }
}
